!------------------------------------------------------------------------------
! TJU/Department of Mechanics, Fluid Mechanics, Code START
!------------------------------------------------------------------------------
!> @Author: Jianxin Liu shookware@tju.edu.cn
!> @Date: 2024-08-02 16:53:09
!> @LastEditTime: 2024-08-06 11:34:30
!> @LastEditors: Jianxin Liu shookware@tju.edu.cn
!> @Description:
!> @FilePath: /START_NS_3D/src/field/module_primitive.f90
!> @Copyright (c) 2024 by Jianxin Liu email: shookware@tju.edu.cn, All Rights Reserved.
!------------------------------------------------------------------------------

module mod_primitive

   use mod_field_base
   use petsc_wrapper_vector
   use petsc_wrapper_print
   implicit none

   private
   public :: type_primitive

   type, extends(type_field_base) :: type_primitive

      type(type_domain_vector), pointer :: rho => null()
      type(type_domain_vector), pointer :: u => null(), v => null(), w => null()
      type(type_domain_vector), pointer :: T => null()
   contains

      procedure, public :: destroy
      generic :: push => push_single, push_multi

      procedure, private :: push_single
      procedure, private :: push_multi

   end type type_primitive

contains

   subroutine push_single(this, prop, value)
      implicit none
      class(type_primitive), intent(inout) :: this
      character(len=*), intent(in) :: prop
      type(type_domain_vector), intent(in), target :: value

      select case (trim(prop))
      case ('rho')
         this%rho => value
      case ('u')
         this%u => value
      case ('v')
         this%v => value
      case ('w')
         this%w => value
      case ('T')
         this%T => value
      case default
         call petsc_error_print('Error: Unknown property: '//prop)
      end select

   end subroutine push_single

   subroutine push_multi(this, rho, u, v, w, T)
      implicit none
      class(type_primitive), intent(inout) :: this
      type(type_domain_vector), intent(in), target :: rho, u, v, w, T

      this%rho => rho
      this%u => u
      this%v => v
      this%w => w
      this%T => T

   end subroutine push_multi

   subroutine destroy(this)
      implicit none
      class(type_primitive), intent(inout) :: this

      nullify (this%rho)
      nullify (this%u)
      nullify (this%v)
      nullify (this%w)
      nullify (this%T)
      nullify (this%eos)

   end subroutine destroy

end module mod_primitive
